package cn.com.klun.tjy.admin.common.Impl;

import java.util.List;
import cn.com.klun.tjy.admin.common.EntityPersistenceLayerService;
import cn.com.klun.tjy.admin.common.LogicsSqlException;
import cn.com.klun.tjy.common.baseInterface.PersistenceLayerSerMapper;
import cn.com.klun.tjy.common.basePojo.Entitys;
import cn.com.klun.tjy.common.basePojo.PageQueryEntitys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class EntityPersistenceLayerServiceImpl implements EntityPersistenceLayerService {
    private Logger logger = LoggerFactory.getLogger("EntityPersistenceLayerServiceImpl");

    public EntityPersistenceLayerServiceImpl() {
    }

    @Override
    public PageQueryEntitys queryPageList(PersistenceLayerSerMapper mapper, PageQueryEntitys entity) throws LogicsSqlException {
        try {
            int count = mapper.queryPageListCount(entity);
            if (count > 0) {
                entity.resetTotalCount(count);
                List<Entitys> resultEntity = mapper.queryPageList(entity);
                entity.setList(resultEntity);
            }

            return entity;
        } catch (Exception var5) {
            this.logger.error("根据条件查询数据集合异常(queryPageList)：", var5);
            throw new LogicsSqlException("0209", "根据条件查询数据集合失败");
        }
    }

    @Override
    public PageQueryEntitys queryPageVoList(PersistenceLayerSerMapper mapper, PageQueryEntitys entity) throws LogicsSqlException {
        try {
            int count = mapper.queryPageListCount(entity);
            if (count > 0) {
                entity.resetTotalCount(count);
                List<Entitys> resultEntity = mapper.queryPageVoList(entity);
                entity.setList(resultEntity);
            }

            entity.setTotalCount(count);
            return entity;
        } catch (Exception var5) {
            this.logger.error("根据条件查询数据集合异常(queryPageVoList)：", var5);
            throw new LogicsSqlException("0210", "根据条件查询数据集合失败");
        }
    }
}
